package com.sunnuwell.demo.common.advice;

import com.sunnuwell.demo.common.exception.AdException;
import com.sunnuwell.demo.common.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/** 
* @Description: 全局异常处理 
* @Param:  
* @return:  
* @Author: Mr.Lv 
* @Date: 2019/3/26 
*/ 
@RestControllerAdvice
public class GlobalExceptionAdvice {

    // 只处理一种异常
    @ExceptionHandler(value = AdException.class)
    public CommonResponse<String> handlerAdException(HttpServletRequest req,
                                                     AdException ex) {
        CommonResponse<String> response = new CommonResponse<>(ex.getCode(),
                ex.getMessage(),null);
//        response.setData(ex.getMessage());
        return response;
    }
}
